<template>
    <div class="layout">
        <div class="layout" ref="MapView"></div>
        <div class="control">
            事件名称 :{{EventName}}
            <br><br>
            经度 ： <span>{{longitude}}</span>
            <br>
            纬度 ： <span>{{latitude}}</span>
            <br>
            高度 ： <span>{{height}}</span>
        </div>
    </div>
</template>
<script>
import simpleMap from '@best/libs-cli/simpleMap/index.js'

var map = null;
var mapConfig = [{
    "type": "TD",
    "name": "天地图",
    "layerType": "background",
    "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
    "default": false
}]
export default {
    data() {
        return {
            EventName: '',
            longitude: '',
            latitude: '',
            height: '',
        }
    },
    mounted() {
        map = simpleMap.initMap(this.$refs.MapView);
        map.addProviders(mapConfig);
        // 绑定左键单击事件
        map.on('Click', (item) => {
            this.EventName = '左键点击';
            this.longitude = item.longitude.toFixed(2);
            this.latitude = item.latitude.toFixed(2);
            this.height = item.height.toFixed(2);
        });
        // 绑定右键单击事件
        map.on('RightClick', (item) => {
            this.EventName = '右键点击';
            this.longitude = item.longitude.toFixed(2);
            this.latitude = item.latitude.toFixed(2);
            this.height = item.height.toFixed(2);
        });
        // 绑定双击事件
        map.on('DBLClick', (item) => {
            this.EventName = '双击';
            this.longitude = item.longitude.toFixed(2);
            this.latitude = item.latitude.toFixed(2);
            this.height = item.height.toFixed(2);
        });
    },
    methods: {
        
    },
    beforeDestroy() {
        // 页面被注销时，销毁地图
        map && map.destroy();
    }
}
</script>

<style scoped>
.layout {
    height: 100%;
    width: 100%;
}

.control {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 20px;
    color: #fff;
}
.title {
    color: #fff;
}
</style>